The following RegEx extract the hour from a 24H time format string like HH:mm (09:30), HH (09), or H (9).
──────────────
Explanation:
• \b: Word boundary to ensure we capture only complete numbers, not parts of larger numbers.
• (?:...): Non-capturing group to match the following alternatives without creating a capture group.
• [01]\d: Matches hours from 0 to 19.
• 2[0-3]: Matches hours from 20 to 23.
• (?=:|$): Lookahead to ensure the hour is followed by a colon : (like in HH:mm) or the end of the string (like in H or HH).